//
//  RegisterViewController.m
//  UI14_豆瓣电影更新版
//
//  Created by dllo on 16/1/4.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "RegisterViewController.h"
#import "LyView.h"
@interface RegisterViewController ()<UITextFieldDelegate>

@end

@implementation RegisterViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)dealloc {
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 右上角button
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    self.navigationItem.rightBarButtonItem = item;
    [item release];
    self.navigationItem.title = @"注册";
    
    // 数据处理
    [self dataHandle];
    
    
    
}
// item方法
- (void)itemAction:(UIBarButtonItem *)item {
    // 获取用户名textField
    UITextField *tf = [self.view viewWithTag:1000];
    //判断用户名是否为空, 如果为空提示 否则 可以注册 提示注册成功
    if (!tf.text.length) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名不能为空" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alert animated:YES completion:^{
            
        }];

    } else {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"注册成功" preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alert animated:YES completion:^{
        
    }];
        
    }
    // alert提示框延迟时间
    [self performSelector:@selector(dismissAlert) withObject:nil afterDelay:1.5];
    
    
}
- (void)dismissAlert{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    UITextField *tf = [self.view viewWithTag:textField.tag + 1];
    [tf becomeFirstResponder];
    return YES;
}



- (void)dataHandle {
    LyView *view = [[LyView alloc] initWithFrame:CGRectMake(20, 40, self.view.frame.size.width, 40)];
    view.label.text = @"用户名:";
    view.textField.placeholder = @"请输入用户名";
    view.textField.delegate = self;
    view.textField.tag = 1000;
    [self.view addSubview:view];
    [view release];
    
    LyView *view2 = [[LyView alloc] initWithFrame:CGRectMake(20, 100, self.view.frame.size.width, 40)];
    view2.label.text = @"密码:";
    view2.textField.placeholder = @"请输入密码";
    view2.textField.secureTextEntry = YES;
    view2.textField.delegate = self;
    view2.textField.tag = 1001;
    [self.view addSubview:view2];
    [view2 release];
    
    LyView *view3 = [[LyView alloc] initWithFrame:CGRectMake(20, 160, self.view.frame.size.width, 40)];
    view3.label.text = @"确认密码:";
    view3.textField.placeholder = @"再次输入密码";
    view3.textField.secureTextEntry = YES;
    view3.textField.delegate = self;
    view3.textField.tag = 1002;
    [self.view addSubview:view3];
    [view3 release];
    LyView *view4 = [[LyView alloc] initWithFrame:CGRectMake(20, 220, self.view.frame.size.width, 40)];
    view4.textField.placeholder = @"请输入邮箱";
    view4.textField.delegate = self;
    view4.label.text = @"邮箱:";
    view4.textField.tag = 1003;
    [self.view addSubview:view4];
    [view4 release];
    
    LyView *view5 = [[LyView alloc] initWithFrame:CGRectMake(20, 280, self.view.frame.size.width, 40)];
    view5.label.text = @"联系方式:";
    view5.textField.placeholder = @"请输入联系方式";
    view5.textField.delegate = self;
    view5.textField.tag = 1004;
    [self.view addSubview:view5];
    [view5 release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
